package com.example.vote.flow.controller;

import com.example.vote.flow.pojo.core.Principle;
import com.example.vote.flow.pojo.param.VoteRecordAddNewParam;
import com.example.vote.flow.service.IVoteRecordService;
import com.example.vote.flow.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "4. 投票记录管理模块")
@RestController
@RequestMapping("/api/vote-record")
public class VoteRecordController {

    @Autowired
    private IVoteRecordService voteRecordService;

    @ApiOperationSupport(order = 100)
    @Operation(summary = "[用户] 投票")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@ParameterObject VoteRecordAddNewParam param, HttpServletRequest request) {
        String ipAddress = request.getRemoteAddr();
        HttpSession session = request.getSession();
        Principle principle = (Principle) session.getAttribute(Principle.SESSION_KEY);
        voteRecordService.addNew(param, principle, ipAddress);
        return JsonResult.ok();
    }

}
